<!doctype html>
<html ng-app="myApp">
<head>
  <meta charset="utf-8" />
  <script src="js/angular.js"></script>
</head>
<body>

  <!-- type any number into the text field -->

  <div ng-controller="EquationController">
    <input type="text" ng-model="equation.x" ng-change="change()" placeholder="输入一个数字"/>
    <code>{{ equation.output }}</code>
  </div>

  <script>
    angular.module('myApp', [])
    .controller('EquationController', function($scope) {
      $scope.equation = {};
      $scope.change = function() {
        $scope.equation.output = Number($scope.equation.x) + 2;
      };
    });
  </script>

</body>
</html>